package control

import (
	"net/http"
	"pro_cla_sql/model"
	"pro_cla_sql/util"
)

func Sinfos(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)
	cid := CSno[0:10]
	println(cid[0:10])
	// print(sno)
	mod, err := model.SinfosAll(cid)
	if err != nil {
		w.Write(util.NewResult(util.Fail, "个人信息查询失败"))
		return
	} else {
		w.Write(util.NewResult(util.Success, "个人信息查询成功", mod))
		return
	}

}
func SinfosOne(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)
	// print(sno)
	mod, _, _, _, _, err := model.SinfosOne(CSno)
	// mod, err := model.SinfosAll(cid)
	if err != nil {
		w.Write(util.NewResult(util.Fail, "个人信息查询失败"))
		return
	} else {
		w.Write(util.NewResult(util.Success, "个人信息查询成功", mod))
		return
	}

}
func Sinfoupdate(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)
	r.ParseForm()
	var hobby = r.FormValue("hobby")
	var tel = r.FormValue("phone")
	var content = r.FormValue("content")
	ok := model.Sinfoupdate(hobby, tel, content, CSno)
	if ok {
		w.Write(util.NewResult(util.Success, "修改成功"))
	} else {
		w.Write(util.NewResult(util.Fail, "修改失败"))
	}

}
